package com.base.lib;

import android.content.Context;
import android.support.multidex.MultiDexApplication;

import com.amap.api.location.AMapLocation;
import com.base.lib.net.ApiClient;
import com.base.lib.net.ApiConfiguration;
import com.base.lib.net.ApiConstants;
import com.base.lib.utils.SdCard;

import me.jessyan.autosize.AutoSizeConfig;
import me.jessyan.autosize.unit.Subunits;

//import com.jh3502.vivo.base.BaseCrash;

public class MyApplication extends MultiDexApplication {
    private static final String TAG = "Jh3502HelperApplication";
    private static Context sAppContext;
    private static AMapLocation sMapLocation;
    private String cityListCity;

    public static void initApiClient(int whichService) {
        ApiConfiguration apiConfiguration = ApiConfiguration.builder()
                .dataSourceType(whichService)
                .build();
        ApiClient.init(apiConfiguration);
    }

    public static Context getAppContext() {
        return sAppContext;
    }

    public static AMapLocation getMapLocation() {
        return sMapLocation;
    }

    public static void setMapLocation(AMapLocation mapLocation) {
        sMapLocation = mapLocation;
    }

    public String getCityListCity() {
        return cityListCity;
    }

    public void setCityListCity(String cityListCity) {
        this.cityListCity = cityListCity;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        initAutoSize();
//        BaseCrash.getInstance().init(this);
        SdCard.getInstance().mkdirs();

        sAppContext = this.getApplicationContext();
//        initApiClient(ApiConstants.DATA_SOURCE_TYPE_ONLINE);
//        initApiClient(ApiConstants.DATA_SOURCE_TYPE_TEST);
        initApiClient(ApiConstants.DATA_SOURCE_TYPE_DEV);
    }

    private void initAutoSize() {
        AutoSizeConfig.getInstance().getUnitsManager()
                .setSupportDP(false)
                .setSupportSP(false)
                .setSupportSubunits(Subunits.MM);
    }
//    private void initGreenDao() {
//        //DevOpenHelper每次数据库升级会清空数据，一般用于开发
//        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this,"easyMvp_db",null);
//        Database db = helper.getWritableDb();
//        mDaoSession = new DaoMaster(db).newSession();
//    }
//
//    public static DaoSession getDaoSession(){
//        return mDaoSession;
//    }
}
